<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="author" content="Kodinger">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>My Login Page</title>
    <link rel="stylesheet" href="../static/css/bootstrap.min.css"
          integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
        <link href="../static/css/bootstrap.min.css" type='text/css' rel="stylesheet">
    <link href="../static/css/dashboard.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="../static/css/my-login.css">
</head>

<script src="../static/js/jquery.min.js" type="text/javascript" charset='utf-8'></script>

<script type="text/javascript">
    // 初始化界面
    $(function () {
        // 判断是否登录
        $.get('http://127.0.0.1:5000/check_login', {},
            function (data) {
                console.log(data);
                if (data['login'] === false) {
                    // window.location.href = "/"
                } else {
                    window.location.href = "index.html"
                }
            }
        );

        $("#login_submit").click(function () {
            const email = $("#email").val();
            const password = $("#password").val();

            console.log(email);
            console.log(password);

            if ((email === undefined) || (password === undefined) || (email === '') || (password === '')) {
                alert('邮箱或密码不能为空！');
                return
            }

            $.get('http://127.0.0.1:5000/login/' + email + '/' + password, {},
                function (data) {
                    if (data['status'] == 'ok') {
                        alert('登录成功！');
                        window.location.href = "index.html"
                    } else {
                        alert('账户不存在或密码错误！');
                    }
                }
            );
        });
    });
</script>


<body class="my-login-page">
<section class="h-100">
    <div class="container h-100">
        <div class="row justify-content-md-center h-100">
            <div class="card-wrapper">
                <div class="brand">
                    <img src="../static/img/user_logo.jpg" alt="logo">
                </div>
                <div class="card fat">
                    <div class="card-body">
                        <h4 class="card-title">登录</h4>
                        <div class="my-login-validation" novalidate="">
                            <div class="form-group">
                                <label for="email">邮箱</label>
                                <input id="email" type="email" class="form-control" name="email" value="" required
                                       autofocus>
                            </div>

                            <div class="form-group">
                                <label for="password">密码
                                </label>
                                <input id="password" type="password" class="form-control" name="password" required
                                       data-eye>
                            </div>

                            <div class="form-group">
                                <div class="custom-checkbox custom-control">
                                    <input type="checkbox" name="remember" id="remember" class="custom-control-input" checked="checked">
                                    <label for="remember" class="custom-control-label">记住密码</label>
                                </div>
                            </div>

                            <div class="form-group m-0">
                                <button type="submit" class="btn btn-primary btn-block" id="login_submit">
                                    登录
                                </button>
                            </div>
                            <div class="mt-4 text-center">
                                还没有账号? <a href="register_page">注册</a>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="footer">
                    <!--						Copyright &copy; 2017 &mdash; Your Company -->
                </div>
            </div>
        </div>
    </div>
</section>

<script src="../static/js/bootstrap.min.js"
        integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
        crossorigin="anonymous"></script>
<script src="../static/js/my-login.js"></script>
<script src="../static/js/jquery.min.js" type="text/javascript" charset='utf-8'></script>
<script src="../static/js/bootstrap.min.js" type="text/javascript"></script>
</body>
</html>
